package com.atguigu.paymentdemo.controller;

import com.atguigu.paymentdemo.entity.ProductInfo;
import com.atguigu.paymentdemo.service.OrderInfoService;
import com.atguigu.paymentdemo.service.ProductInfoService;
import com.atguigu.paymentdemo.service.impl.OrderInfoServiceImpl;
import com.atguigu.paymentdemo.service.impl.ProductInfoServiceImpl;
import com.atguigu.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@CrossOrigin//开放前端跨域

@RestController//对于负责Restful API交互的功能模块,该类中所有的API接口返回的数据，
// 甭管返回Map或是其他Object，都以Json字符串的形式返回给客户端
@RequestMapping("api/product")
@Api(tags="商品管理")
public class ProductController {
    @Autowired
    private ProductInfoService productInfoService;
    @GetMapping("/test")
    @ApiOperation("测试接口")
    public R test(){
        return R.ok().data("message","hello").data("now",new Date());
    }

    @GetMapping("/list")
    @ApiOperation("商品列表")
    public  R list(){

        List<ProductInfo> list = productInfoService.list();
        return R.ok().data("productList",list);
    }

}
